<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<title>S-Pet Writer</title>
<link rel="stylesheet" type="text/css" href="css/1128.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0-rc.1/jquery.mobile.structure-1.4.0-rc.1.min.css" />
<!-- <link href="lib/jquery.mobile-1.3.2.css" type="text/css" rel="stylesheet"> -->
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
	<script type="text/javascript" charset="utf-8" src="phonegap-nfc.js"></script>
	<script type="text/javascript" charset="utf-8" src="phonegap-toast.js"></script>
	<script type="text/javascript" charset="utf-8" src="js/jquery.urlshortener.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/write.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/pic.js"></script>
   	<script type="text/javascript">
///////////////////
	var hash = new Date().getTime();
	//사진 소스 선택(가져오기, 새로찍기)
	function SrcSlt(){
		navigator.notification.confirm(
			"사진을 어디서 가져올까요?",
					function(btnNo){
				if(btnNo == 1){
					LoadPic();
				}else if(btnNo == 2){
					capture();
				}
			},
			"선택",
			"가져오기,새로찍기"
		);
	}
	
    function capture() {
    	// Retrieve image file location from specified source
    	navigator.camera.getPicture(getImageURI, function(message) {
    	alert('Image Capture Failed');
    	}, {
    		quality : 100,
    		destinationType : Camera.DestinationType.FILE_URI
    		});
    	}
    
    function LoadPic() {
    	// Retrieve image file location from specified source
    	navigator.camera.getPicture(getImageURI, function(message) {
    	alert('Image Capture Failed');
    	}, {
    		quality : 100,
			destinationType : navigator.camera.DestinationType.FILE_URI,
			sourceType : navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
    		});
    	}
    
    	//file system fail 
    	function fsFail(error) { 
    	    alert("failed with error code: " + error.code); 
    	}
    	
    	function getImageURI(imageURI) {
        	var gotFileEntry = function(fileEntry) { 
        			var PicAddress =  "/AAA/img/" + hash + ".jpg";
        	        alert("got image file entry: " + fileEntry.fullPath); 
        	        var gotFileSystem = function(fileSystem){ 
        	            // copy the file 
        	            fileEntry.copyTo(fileSystem.root, PicAddress, null, null); 
        	       }; 
        	        // get file system to copy or move image file to 
        	        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail); 
        	    }; 
        	    //resolve file system for image  
        	    window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail); 
        	    var image = document.getElementById('image');
				image.style.display = 'block';
				image.src = imageURI;
        	}
    ///////////////////
     $(function(){
		$('#hash').val(hash);
		wrt.init();
//    	app.initialize();
    });
    
 	function handleOpenURL(url) {
	    alert("Write페이지입니다.\n(태그 내용 확인)\n received url: " + url);
		if(url == 'spet://write'){
//			window.location.replace('write.html');
		}else if(url != ''){
//			window.location.replace(url);
		}
	}
</script>
</head>
<body>
	<!-- 메인화면 content 메뉴 -->
	<div data-role="page">
		<div data-role="header" data-position="fixed">
			<a href="#main" data-icon="home" class="ui=btn-left">Main App</a>
			<h1>Write TAG</h1>
			<a href="#"	data-icon="refresh">menu1</a>
		</div>
		
		<div data-role="content" data-theme="a">
			<form method="GET">
				<h2>TAG에 입력할 내용을 작성 후 탭</h2>
				<input type="text" name="i" id="hash" readonly="readonly"/>
				<input type="text" name="n" class="input" placeholder="동물이름*" required="required" value="은비"/>
				<input type="text" name="o" class="input" placeholder="색깔*" value="황갈색"/>
				<input type="text" name="t" class="input" placeholder="전화번호*" required="required" value="010-6761-1144"/>
				<input type="text" name="m" class="input" placeholder="특이사항*" required="required" value="멍멍 짖음 + ㅎㅎㅎ"/>
				<input type="text" name="c" class="input" placeholder="사례정보(단위: 만원, 선택입력)*" value="2000"/>
				<input type="text" name="r" class="input" placeholder="등록번호(15자리)" value="1234"/>
<!-- 				<input type="submit" value="입력완료"> -->
			</form>
		</div>	

				<input type="text" name="mimetype" class="input" placeholder="마임타입" required="required" value="text/spet"/>
				<input type="text" name="url" class="input" placeholder="URL*" required="required" value="http://llun.com/in"/>
				<input type="text" name="payload" class="input" placeholder="특이사항*" required="required" value="http://llun.com/in"/>
    <button class="btn large" onclick="SrcSlt();">사진 업로드</button>
	<div>
			<img id="image" style="display:none;width:290px;height:210px;" src="" align="top"/>
	</div> 
    <div id="viewport" class="viewport" style="display:none;">
      <img style="width:320px;height:240px;" id="photo" src=""/>
    </div>
</div>
</body>
</html>